{extend name="public:base"}
{block name="body"}
<body>
		<form class="layui-form layui-form-pane" action="">
			<div class="mainBox">
				<div class="main-container">
                   <div class="layui-row">
                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                            <div class="layui-form-item">
                                <label class="layui-form-label">分类名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="title" value="{$info.title|default=''}" lay-verify="required" autocomplete="off"
                                        placeholder="请输入标题" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                            <div class="layui-form-item">
                                <label class="layui-form-label">所属模块</label>
                                <div class="layui-input-block">
                                    <select name="module_id" lay-verify="require">
                                        {volist name="module" id="vo"}
                                        <option value="{$vo.id}" {present name="info.module_id"} {eq name="info.module_id" value="$vo['id']"} selected {/eq} {/present}>{$vo.title}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                            <div class="layui-form-item">
                                <label class="layui-form-label">上级分类</label>
                                <div class="layui-input-block">
                                    <select name="pid" lay-verify="require">
                                        <option value="0">顶级分类</option>
                                        {volist name="category" id="vo"}
                                        <option value="{$vo.id}" {present name="info.id"} {eq name="info.pid" value="$vo['id']"} selected {/eq} {/present}>{$vo.showName}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                            <div class="layui-form-item">
                                <label class="layui-form-label">缩略图</label>
                                <div class="layui-input-block" style="left:5px;">
                                     <button class="pear-btn pear-btn-primary" type="button" id="thumbBtn">图片上传(尺寸100*100)</button>
                                    <div class="upload_img_list" >
                                        <div class="img_list" id="upload_box_thumb">
                                            <img src="{$info.thumb|default='/assets/library/admin/images/no_img.png'}" style="width:100px;max-width:100px" />
                                            <input type="hidden" name="thumb" value="{$info.thumb|default=''}">
                                        </div>
                                        
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                            <div class="layui-form-item">
                                <label class="layui-form-label">首页菜单</label>
                                <div class="layui-input-block">
                                    <select name="is_show" lay-verify="require">
                                        <option value="0" >否</option>
                                        <option value="1" {present name="info.is_show"} {eq name="info.is_show" value="1"} selected {/eq} {/present}>是</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        
                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                            <div class="layui-form-item">
                                <label class="layui-form-label">排序</label>
                                <div class="layui-input-block">
                                    <input type="text" name="sort" value="{$info.sort|default='100'}" lay-verify="required" autocomplete="off"
                                        placeholder="排序" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                            <div class="layui-form-item">
                                <label class="layui-form-label">备注</label>
                                <div class="layui-input-block">
                                    <textarea name="remark" placeholder="备注" class="layui-textarea">{$info.remark|default=''}</textarea>
                                </div>
                            </div>
                        </div>
                   </div>
                </div>
            </div>
            <div class="bottom">
            <div class="button-container">
                <input type="hidden" name="id" value="{$info.id|default=''}">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="form-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
            </div>
		</form>
	</body>
{/block}
{block name="script"}
<script>
    layui.use(['jquery','form','upload'], function() {
        let form = layui.form;
        let $ = layui.jquery;
        let upload =layui.upload;
        layui.upload.render({
			elem: '#thumbBtn'
			, url: '{:url("ajax/upload")}'
			, done: function (res) {
				//如果上传失败
				if (res.code == 0) {
					return layer.msg('上传失败');
				}
				//上传成功
				
				$('#upload_box_thumb input').attr('value', res.data);		
				$('#upload_box_thumb img').attr('src', res.data);
			}
		});
        form.on('submit(form-save)', function(data) {
            $.ajax({
                url: '{:url("edit")}',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function(result) {
                    if (result.code == 1) {
                        layer.msg('操作成功', {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
                            parent.layui.table.reload("table-list");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
{/block}
